//
//  SKUDetailFourCell.m
//  Tang
//
//  Created by 352324497@qq.com on 15/12/8.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "SKUDetailFourCell.h"
#import "SKUDetailFourCellCell.h"
#import "SKUDetailFourModel.h"
@implementation SKUDetailFourCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = NO;
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        self.SKUDetailFourCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0 * Kx6, 0, KWidth, KHeight - 84 * Kx6) collectionViewLayout:layout];
        self.SKUDetailFourCollectionView.showsVerticalScrollIndicator = NO;
        self.SKUDetailFourCollectionView.backgroundColor = [UIColor whiteColor];
        self.SKUDetailFourCollectionView.showsVerticalScrollIndicator = NO;
        self.SKUDetailFourCollectionView.scrollEnabled = NO;
        self.SKUDetailFourCollectionView.delegate = self;
        self.SKUDetailFourCollectionView.dataSource = self;
        
        [self.SKUDetailFourCollectionView registerClass:[SKUDetailFourCellCell class] forCellWithReuseIdentifier:@"cell"];
        
        [self.contentView addSubview:_SKUDetailFourCollectionView];
        
        self.modelArray = [NSMutableArray array];
    }
    return self;
}

-(void)setItemsWithArray:(NSMutableArray *)array
{
    if (array.count != 0)
    {
        self.modelArray = array;
        self.SKUDetailFourCollectionView.height = (242 * Kx6 + 10 * Kx6) * self.modelArray.count / 2;
        [self.SKUDetailFourCollectionView reloadData];
    }
}

#pragma mark - Collection

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0 * Kx6, 10 * Kx6, 10 * Kx6, 10 * Kx6);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(170 * Kx6, 242 * Kx6);
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.modelArray.count != 0)
    {
        return self.modelArray.count;
    }
    return 0;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SKUDetailFourCellCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (self.modelArray.count != 0)
    {
        SKUDetailFourModel *model = self.modelArray[indexPath.item];
        cell.model = model;
    }
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.delegate respondsToSelector:@selector(selectedCollectionWithIndexpath:)])
    {
        [self.delegate selectedCollectionWithIndexpath:indexPath];
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
